<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';

$pd=new pdo_mysql();
$filter=new Filter();
session_start();

/*if(empty($_SESSION['uid'])){
    $tips=array(
		'tips'=>'请登录后再进行操作',
		'url'=>'index.php'
	);
	$tips=urlencode(serialize($tips));
	header('Location:../tips.php?gets='.$tips);
	exit;
}*/

$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
    $now=date('Y-m-d H:i:s');
	$id          =empty($_POST['id'])?0:Filter::filter_number($_POST['id']);
	$deptname  = Filter::safe_string($_POST['deptname']);
	$depttype    =empty($_POST['depttype'])?0:Filter::filter_number($_POST['depttype']);
	$mech        =empty($_POST['mech'])?0:Filter::filter_number($_POST['mech']);
	$flag        =empty($_POST['flag'])?0:Filter::filter_number($_POST['flag']);
	$odx         =empty($_POST['odx'])?0:Filter::filter_number($_POST['odx']);

	$in_data=array(
		'deptname' =>$deptname,
		'depttype' =>$depttype,
		'mech'     =>$mech,
		'flag'     =>$flag,
		'odx'      =>$odx
	);
	$result=0;
	$tps='';
	if($id==0){
		$result=$pd->insert(array('data'=>$in_data,'table'=>'sys_department'));
		$tps='添加成功';
	}else{
		$result=$pd->update(array('data'=>$in_data,'table'=>'sys_department','where'=>"id=".$id));
		$tps='修改成功';
	}
	if(empty($result)){
		$tips=array(
			'tips'=>'更新失败。',
			'url' =>'./?t=system_dept'
		);
		$tips=urlencode(serialize($tips));
		header('Location:/tips.php?gets='.$tips);
	}else{
		$tips=array(
			'tips'=>$tps,
			'url' =>'./?t=system_dept'
		);
		$tips=urlencode(serialize($tips));
		header('Location:/tips.php?gets='.$tips);
	}
}else{
	$tips=array(
		'tips'=>'不允许的表单提交方式，请按正常流程提交表单。',
		'url'=>'index.php'
	);
	$tips=urlencode(serialize($tips));
	header('Location:/tips.php?gets='.$tips);
}
?>